#ifndef NETMAIN_H
#define NETMAIN_H

#include <QObject>
#include <QJsonArray>
class QTcpSocket;
class NetMain : public QObject
{
    Q_OBJECT
protected:
    explicit NetMain(QObject *parent = nullptr);

public:
    static NetMain *getObject();
    /**
     * @brief carPosChanged 车辆位置发生改变
     * @param roundId
     * @param roundPos
     */
    void carPosChanged(int roundId, int roundPos);

signals:
    void setCarAlarmSig(bool sw);
    void setCarAlarmLightSig(bool sw);
    void setCarLightSig(bool sw);
    void setCarStatusSig(bool sw);


protected slots:
    void clientReadyReadSlot();


protected:
    void connectToHost();
    void sendIdentity();
    void handleFrame(const QJsonObject &obj);
    void handleCarAlarmFrame(const QJsonObject &obj);
    void handleCarAlarmLightFrame(const QJsonObject &obj);
    void handleCarLightFrame(const QJsonObject &obj);
    void handleCarStatusFrame(const QJsonObject &obj);


    static NetMain *obj;
    QTcpSocket *client;

};

#endif // NETMAIN_H
